//创建注册界面
function createRegisterInterface(){
  $("#loginDiv").html("");
  //修改这里的值msgTarget:"title"  msgTarget:"under"  msgTarget:"side"
  var mailRegex = /^\s*\w+([-+.']\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*(\;\w+([-+.']\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*)*(\;)*\s*$/;
  new Ext.Panel({
       renderTo: "loginDiv",
       title: "注册界面",
       width: 388,
       layout: "form",
       labelAlign: "right",
       defaultType: "textfield",
       style:"margin-left:-18",
       items:[
         {fieldLabel:"<font color='red'>*</font>输入用户账号",name:"userName",style:"margin-top: 2",allowBlank:false, blankText:"用户账号不能为空",msgTarget:"under" },
         {fieldLabel:"<font color='red'>*</font>输入用户密码",name:"userPassword",inputType:"password",allowBlank:false, blankText:"用户密码不能为空",msgTarget:"under" },
         {fieldLabel:"<font color='red'>*</font>重复输入密码",name:"userPassword2",inputType:"password",allowBlank:false, blankText:"重复密码不能为空",msgTarget:"under" },
         {fieldLabel:"<font color='red'>*</font>输入邮箱地址", name:"userMail",allowBlank:false, blankText:"邮箱地址不能为空",msgTarget:"under" ,vtype:"email",vtypeText:"邮件格式不正确"}
         
       ],
       buttons:[
         {
           text:"提交",
           handler: function(){
             saveUserInfo();
           }
         },
         {
           text:"进入登录",
           handler: function(){
             createLoginInterface();
           }
         }
       ]
  });
  //保存用户注册信息
  function saveUserInfo(){
     var userName = $("input[name='userName']").val();
     var userPassword = $("input[name='userPassword']").val();
     var userPassword2 = $("input[name='userPassword2']").val();
     var userEmail = $("input[name='userMail']").val();
     if(userName == ""){
       return;
     }
     if(userPassword == ""){
       return;
     }
     if(userPassword != userPassword2){
       showMessage("两次输入的密码不一样，请重新输入！","error");
       return;
     }
     var checkFlag = checkUserInfo(userName,userPassword,userEmail);
     if(checkFlag){
         var dataParam = "userVO.userName=" + userName + "&userVO.userPassword=" + userPassword + "&userVO.userEmail=" + userEmail;
	     $.ajax({
	        type:"POST",
	        url:"saveUserInfo.action",
	        data: dataParam,
	        success: function(result){
	           initLoginInfoAfterReg(userName);
	           $("#loginDivPanel").dialog("close");
	           showSystemErrorMsg(result);
	        }
	        
	     });
     }
  }
  
}
//注册之后，初始化欢迎信息
function initLoginInfoAfterReg(userName){
  $("#loginInfo").html("欢迎您：" + userName);
}
//判断输入的用户名和密码是否已经存在，如果已经存在，则给出提示信息
function checkUserInfo(userName,userPassword,userEmail){
     var returnFlag = true;
     $.ajax({
        type:"POST",
        url:"checkUseEmail.action",
        data: "userVO.userEmail=" + userEmail,
        async: false,
        success: function(result){
           if("0" != result){
              showMessage("您注册的邮箱地址已存在，请重新填写！","error");
              returnFlag = false;
           }
          
        }
     });
     
     if(returnFlag){
          $.ajax({
              type:"POST",
              url:"checkUserInfo.action",
              async: false,
              data:"userVO.userName=" + userName + "&userVO.userPassword=" + userPassword,
              success: function(result){
                  if("0" != result){
	              showMessage("您注册的用户信息已存在，请重新填写！","error");
	               returnFlag = false;
                  }
              }
           });
     }
     return returnFlag;
}